home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / launchpad-integration / launchpadintegration / urls.py < prev    next >
Text File  |  2009-09-24  |  3KB  |  67 lines

  1. import urlparse
  2. import subprocess
  3. import os
  4.  
  5. def showUrl(url, logger=None):
  6.     """Show the given URL in the user's preferred browser.
  7.  
  8.     Currently just shells out to gnome-open, which uses the browser
  9.     picked in the Gnome "preferred applications" control panel.
  10.     If firefox is used open a new window.
  11.     If Gnome is not available it uses the x-www-browser setting
  12.     """
  13.     if logger:
  14.         logger.info('opening URL %s', url)
  15.     
  16.     if os.environ.get('GNOME_DESKTOP_SESSION_ID') and os.path.exists('/usr/bin/gnome-open'):
  17.     command = ['gnome-open', url]
  18.     if os.path.exists('/usr/bin/gconftool-2'):
  19.         gconf_key = os.popen('gconftool-2 --get /desktop/gnome/url-handlers/http/command')
  20.         if gconf_key.read().strip() == 'firefox %s':
  21.             if (subprocess.call(['firefox', '-remote', 'ping()'], stderr=open('/dev/null', 'w')) == 0):
  22.                 command = ['firefox', '-remote', 'openURL(%s, new-window)'%url]
  23.             else:
  24.                 command = ['firefox', url]
  25.     elif os.environ.get('KDE_FULL_SESSION') and os.path.exists('/usr/bin/kfmclient'):
  26.         command = ['kfmclient', 'openURL', url]
  27.     else:
  28.         command = ['x-www-browser', url]
  29.  
  30.     # check if we run from sudo (happens for e.g. gnome-system-tools, synaptic)
  31.     if os.getuid() == 0 and os.environ.has_key('SUDO_USER'):
  32.         command = ['sudo', '-u', os.environ['SUDO_USER']] + command
  33.  
  34.     p = subprocess.Popen(command,
  35.                          close_fds=True,
  36.                          stdin=subprocess.PIPE,
  37.                          stdout=subprocess.PIPE)
  38.     p.communicate()
  39.     return p.returncode
  40.  
  41. def launchpadDistroPrefix(facet=None):
  42.     if facet is None:
  43.         prefix = ''
  44.     else:
  45.         prefix = '%s.' % facet
  46.     distro = subprocess.Popen(['lsb_release', '--id', '--short'],
  47.                               stdin=subprocess.PIPE,
  48.                               stdout=subprocess.PIPE).communicate()[0].strip()
  49.     release = subprocess.Popen(['lsb_release', '--codename', '--short'],
  50.                                stdin=subprocess.PIPE,
  51.                                stdout=subprocess.PIPE).communicate()[0].strip()
  52.     return 'https://%slaunchpad.net/%s/%s/' % (prefix, distro.lower(), release)
  53.  
  54. def getSourcePackageUrl(pkginfo, facet=None):
  55.     prefix = launchpadDistroPrefix(facet)
  56.     return urlparse.urljoin(prefix, '+source/%s/' % pkginfo.sourcepackage)
  57.  
  58. def getInfoUrl(pkginfo):
  59.     return urlparse.urljoin(getSourcePackageUrl(pkginfo, 'answers'),
  60.                             '+gethelp')
  61.  
  62. def getTranslateUrl(pkginfo):
  63.     return getSourcePackageUrl(pkginfo, 'translations')
  64.  
  65. # def getBugURL(pkginfo):
  66. #     return urlparse.urljoin(getSourcePackageUrl(pkginfo, 'bugs'), '+bugs')
  67.